package com.easyidea.its.domain.repository.system.impl;

import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.easyidea.its.domain.model.system.Permission;
import com.easyidea.its.domain.repository.base.impl.BaseRepositoryImpl;
import com.easyidea.its.domain.repository.system.PermissionRepository;

/**
 * 
 * @author hukn
 *
 */
public class PermissionRepositoryImpl extends BaseRepositoryImpl<Permission>
		implements PermissionRepository {
	@SuppressWarnings("unchecked")
	public Collection<Permission> getAllPermissions() {
		Criteria criteria = this.createCriteria();
		// criteria.add(Expression.eq("deleted", false));
		return listBeans(criteria, -1, -1);
	}

	public List<Permission> getAllPerssionsByParentId(Integer parentId) {
		// TODO Auto-generated method stub

		Criteria ca = this.createCriteria();
		// ca.add(Restrictions.isNotNull("parentId"));
		if (parentId == null) {
			ca.add(Restrictions.isNull("parentId.id"));
		} else {
			ca.add(Restrictions.eq("parentId.id", parentId));
		}

		ca.addOrder(Order.asc("code"));
		return ca.list();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.infowarelab.elearning.domain.repository.permission.PermissionRepository
	 * #getUserPermissionList(java.lang.Integer)
	 */
//	public List<Permission> getUserPermissionList(Integer userId) {
//		String hql = "select p from com.infowarelab.elearning.domain.model.User as u inner join u.roleId as r inner join r.permissionList as p where u.id = ?";
//
//		return (List<Permission>) this.listBeansByHql(hql, -1, -1, userId);
//	}

}
